package com.lq.util;

public class Pager {
	private int pageSize; //每页显示数据条数
	private int currentPage; //当前页面
	private int totalRecord; //总数据条数
	private int totalPage;//总页面数
	
	//首页
	private int firstPage;
	//末页
	private int lastPage;
	//上一页
	private int prePage;
	//下一页
	private int nextPage;
	

	
	public Pager() {
		
	}
	
	public Pager(int currentPage,int pageSize,int totalRecord) {
		this.pageSize=pageSize;
		this.totalRecord=totalRecord;
		this.totalPage=calculateTotalPage();
		//负责计算 
	}
	
	//计算总页面
	private int calculateTotalPage() {
		this.totalPage=this.totalRecord/this.pageSize;    //总页面数=总数据条数/每页显示数据条数
		if(totalRecord%pageSize!=0) {		             //如果总数据条数%每页显示数据条数!=0  10    5
			this.totalPage=this.totalPage+1;	        //总页数+1
		}
		return totalPage;
	}
	
	
	
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getTotalRecord() {
		return totalRecord;
	}
	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	
	
	
	//首页
	public int getFirstPage() {
		this.firstPage=1;
		return this.firstPage;
	}


	//末页 也就是总的页面
	public int getLastPage() {
		this.lastPage=totalPage;
		return lastPage;
	}

	//上一页
	public int getPrePage() {
		if(this.currentPage<=1) {
			this.prePage=-1;
		}else {
			this.prePage=this.currentPage-1;
		}
		return this.prePage;
	}

	
	//下一页
	public int getNextPage() {
		if(this.currentPage>=totalPage) {
			this.nextPage=-1;
		}else {
			this.nextPage=this.currentPage+1;
		}
		return this.nextPage;
	}
	
	//开始索引
	public int getStartIndex() {
		return (currentPage-1)*pageSize;
	}
	
}
